/**
 * 
 */
package com.nars.strings;

import java.util.Scanner;

/**
 * @author Student
 * 
 */
public class TagCatcher {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		/*
		 * Scanner input = new Scanner(System.in);
		 * System.out.println("Enter a String: ");
		 */
		// String string = input.nextLine();

		String startTag = "<upcase>";
		String endTag = "</upcase>";		

		String string = "We are living in a <upcase>yellow submarine</upcase>. "
				+ "We don't have <upcase>anything</upcase> else.";
		StringBuilder stringBuilder = new StringBuilder(string);
		System.out.println(string);

		int startTagIndex = 0;
		int endTagIndex = 0;

		startTagIndex = stringBuilder.indexOf(startTag);
		while (startTagIndex != -1) {
			endTagIndex = stringBuilder.indexOf(endTag, startTagIndex+1);
			System.out.println("Start index : " + startTagIndex);
			System.out.println("End index : " + endTagIndex);
			String subString = stringBuilder.substring(startTagIndex + startTag.length(), endTagIndex);					
			System.out.println("The Tagged String is : " + subString);
			stringBuilder.replace(startTagIndex,startTagIndex + startTag.length() + subString.length() + endTag.length(),
					subString.toUpperCase());
			startTagIndex = stringBuilder.indexOf(startTag, startTagIndex + 1);
		}
		System.out.println(stringBuilder);

	}

}
